<template>
	<view class="container">
		<u-navbar back-icon-color="#000" :back-text-style="{ color: '#000' }" title-color="#000" back-text="返回" :title="title" :is-fixed="true" :border-bottom="false" :background="navBarBackground">
			<!-- #ifndef MP-WEIXIN -->
			<!-- <view class="navbar-save" slot="right" @tap.stop="saveForm">保存</view> -->
			<!-- #endif -->
		</u-navbar>
		<template v-if="isLoad">
			<u-form class="form" :label-style="labelStyle" ref="uForm">
				<u-form-item label-width="300rpx" :label="param.name" v-for="(param, index) in params" :key="param.alias">
					<view class="form-right">
						<view @tap.stop="clickInput" :data-index="index" :disabled="true" :style="inputStyle" class="form-value">{{ param.setting || '未填写' }}</view>
					</view>
				</u-form-item>
			</u-form>
			<view class="submit-space"></view>
			<view class="submit-area"><u-button @click="saveForm" type="main-theme">保存</u-button></view>

			<!-- <u-select mode="mutil-column" :title="pickerTitle" v-model="twoSelectShow" :list="[twoSelectRangeFirst, twoSelectRangeSecond]" value-name="id" label-name="name"></u-select> -->
			<u-select v-model="regionShow" mode="mutil-column-auto" :list="regionList" @confirm="confirmRegionPicker"></u-select>
			<u-picker mode="selector" :default-selector="selectorDefault" :range="selectorRange" :title="paramTitle" v-model="selectorShow" range-key="name" @confirm="confirmSelector"></u-picker>
			<u-picker mode="multiSelector" :default-selector="twoSelectDefault" :range="[twoSelectRangeFirst, twoSelectRangeSecond]" :title="paramTitle" v-model="twoSelectShow" range-key="name" @confirm="confirmTwoSelector" @columnchange="changeTwoSelect"></u-picker>
			<param-search-manager v-if="itemIndex != null" :defaultValue="params[itemIndex].setting" @cancel="cancelParamSearch" @confirm="confirmParamSearch" v-model="searchPopupShow" :height="searchPopupHeight" :keyname="params[itemIndex].alias" :title="paramTitle"></param-search-manager>
		</template>
	</view>
</template>

<script>
import UserDataMixins from '@/mixins/user-data-mixins.js';
import paramSearchManager from '../components/custom/param-search-manager.vue';
export default {
	mixins: [UserDataMixins],
	components: { paramSearchManager },
	data() {
		return {
			title: '编辑基本资料'
		};
	},
	onLoad() {
		this.getRegionListData();
		this.getData();
	},
	methods: {
		getData() {
			this.$u.api.getUserCoupData().then(res => {
				const coup = res.data.coup;
				const title = `编辑${coup.group_name}`;
				this.params = coup.params;
				this.title = title;
				uni.setNavigationBarTitle({
					title
				});

				this.isLoad = true;
			});
		},

		saveForm() {
			this.$u.api.saveUserCoupData({ coup: this.getAllParams() }).then(res => {
				this.$u.toast('账号信息保存成功');
				this.navigateBack();
			});
		}
	}
};
</script>

<style lang="scss">
@import '@/style/user-data-form.scss';
</style>
